<?php
session_start();
$goodsCart = $_SESSION['carts'];
?>

<html>
<head>
    <title>购物车列表</title>
</head>
<body>
    <ul>
        <?php foreach ($goodsCart as $key => $val):?>
        <li>ID为<?php echo $key;?>的商品，数量为<?php echo $val['num'];?>
            <a href="javascript:delCart(<?php echo $key;?>)">删除</a>
        </li>
        <?php endforeach;?>
    </ul>
</body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
    function delCart(id) {
        if (confirm('是否确定删除该商品')) {
            var params = {
                goods_id: id
            }
            jQuery.post('/c7/delCart.php', params, function(data){
                if (data.status == 200) {
                    window.location.reload()
                } else {
                    alert(data.message);
                }
            }, 'json')
        }

    }
</script>
</html>
